// service/balance/balance.js
import http from "../../utils/http"
import util from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    finish: false,
    loading: false,
    page: 1,
    type: 2,
    money: ''
  },
  // 提现
  withdrawal() {
    util.skip('/service/withdraw/withdraw?type=2')
  },
  // 提现记录
  withdrawalRecord() {
    util.skip('/service/moneyRecord/moneyRecord?type=2')
  },

  detail(e) {
    let id = e.currentTarget.dataset.id;
    if (id) util.skip('/pages/orderDetail/orderDetail?order_id=' + id)
  },
  reload() {
    this.setData({
      list: [],
      page: 1,
      finish: false
    })
    this.getList()
  },
  more() {
    this.setData({
      page: ++this.data.page
    })
    this.getList()
  },
  getList() {
    if (!wx.getStorageSync('token')) return
    if (this.data.finish) {
      return
    }
    if (this.data.loading) {
      return
    }
    this.setData({
      loading: true
    })
    let data = {
      page: this.data.page,
      type: this.data.type
    }

    http.get('withdraw/moneyInfo', data).then(res => {
      if (res.data.list.length === 0) {
        this.setData({
          finish: true
        })
      }
      let arr = this.data.list.concat(res.data.list)
      this.setData({
        list: arr,
        money: res.data.money
      })

    }).finally(res => {
      this.setData({
        loading: false
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  onShow(){
    this.reload()
  }
})